package algotithm.jianzhioffer.test09;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author zhouyanxiang
 * @Date 2020-12-2020/12/14-14:07
 */
public class CQueue {

    Deque<Integer> deque1;
    Deque<Integer> deque2;


    public static void main(String[] args) {

    }

    public CQueue() {
        deque1 = new ArrayDeque<>();
        deque2 = new ArrayDeque<>();
    }

    public void appendTail(int x) {
        deque1.push(x);
    }

    public int deleteHead() {
        if (deque1.isEmpty() && deque2.isEmpty()) {
            return -1;
        }
        while (!deque1.isEmpty()) {
            deque2.push(deque1.pop());
        }
        int x = deque2.pop();
        while (!deque2.isEmpty()) {
            deque1.push(deque2.pop());
        }
        return x;
    }
}
